const mongoose = require("mongoose");
const Schema = mongoose.Schema;

// Create Schema
const UserSchema = new Schema(
  {
    name: {
      type: String,
      required: true,
    },
    phone: {
      type: String,
      required: true,
    },
    password: {
      type: String,
      required: true,
    },
    avatar: {
      type: String,
    },
    realName: {
      type: String,
    },
    plate: {
      type: String,
    },
    type: {
      type: String,
    },
    region: {
      type: String,
    },
    tag: {
      type: Array,
    },
    identity: {
      type: String,
      default: "user",
    },
    // 用户的收货地址
    address: {
      type: Schema.Types.ObjectId,
      ref: "Address",
    },
    // 用户的购物车
    cart: {
      type: Schema.Types.ObjectId,
      ref: "Cart",
    },
    date: {
      type: Date,
      default: Date.now,
    },
  },
  { versionKey: false }
);

module.exports = User = mongoose.model("users", UserSchema);
